package com.ssyx.acl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssyx.acl.service.PermissionService;
import com.ssyx.acl.service.RoleService;
import com.ssyx.common.result.Result;
import com.ssyx.model.acl.Role;
import com.ssyx.vo.acl.RoleQueryVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ClassName:RoleController
 * Description:
 *
 * @Author kay
 * @Create 2024/4/23 17:15
 * @Version 1.0
 */
@Tag(name = "角色接口")
@RestController
@RequestMapping("/admin/acl/role")
//@CrossOrigin
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Operation(summary = "角色条件分页查询")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                        @PathVariable Long limit,
                        RoleQueryVo roleQueryVo){
        Page<Role> pageParam = new Page<>(page, limit);
        //调用service方法实现条件分页查询,返回分页对象
        IPage<Role> pageModel = roleService.getRolePage(pageParam,roleQueryVo);
        return Result.ok(pageModel);
    }

    @Operation(summary = "根据id查询角色")
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        Role role = roleService.getById(id);
        return Result.ok(role);
    }

    @Operation(summary = "添加角色")
    @PostMapping("save")
    public Result save(@RequestBody Role role){
        boolean isSuccess = roleService.save(role);
        if(isSuccess){
            return Result.ok(null);
        }else{
            return Result.fail(null);
        }
    }

    @Operation(summary = "修改角色")
    @PutMapping("update")
    public Result update(@RequestBody Role role){
        roleService.updateById(role);
        return Result.ok(null);
    }

    @Operation(summary = "删除角色")
    @DeleteMapping("remove/{id}")
    public Result removeById(@PathVariable Long id){
        roleService.removeById(id);
        return Result.ok(null);
    }

    @Operation(summary = "批量删除角色")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList){
        roleService.removeBatchByIds(idList);
        return Result.ok(null);
    }

}
